import { http } from '@/plugins/axios'

export default () => {
  const collection = ref<ResponsePageResult<UserModel>>()

  const model = ref<UserModel>()

  const load = async (page = 1, params: Record<any, any> = {}) => {
    collection.value = await http.request<UserModel[], ResponsePageResult<UserModel>>({
      url:
        `user?page=${page}&` +
        Object.entries(params)
          .map(([k, v]) => `${k}=${v}`)
          .join('&'),
    })
  }

  const find = async (id: any) => {
    const { data } = await http.request<UserModel>({
      url: `user/${id}`,
    })
    model.value = data
  }

  return { collection, model, load, find }
}
